package cn.changein.framework.api;

import cn.changein.framework.elasticsearch.respository.EsArticleRepository;
import cn.changein.framework.kernel.model.response.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Date;

/**

 */
@RestController
@RequestMapping("/api/test")
@Slf4j
public class TestController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;


    @Autowired
    EsArticleRepository articleRepository;

    @RequestMapping(value = "")
    public ResponseData test() {
        log.info("api/test");
        return ResponseData.success(stringRedisTemplate.getExpire("hjkhk"));
    }


    @RequestMapping(value = "deleteArticleIndex")
    public ResponseData deleteArticleIndex(String time) throws IOException {
        String nowTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd");
        if (!nowTime.equals(time)) {
            return ResponseData.error("失败");
        }
        articleRepository.deleteIndex();
        return ResponseData.success();
    }

}
